/**
 * Created by wxb on 2017/10/20.
 */
'use strict';

angular.module('BlurAdmin')
  .factory('osgPrefixUrl', function (publicFunc, localStorageService) {
    var imageData = localStorageService.get('osgImageData');
    var videoData = localStorageService.get('osgVideoData');

    var prefix = '/kt/resource/host/';
    var url = {
      image_: {
        url: 'image',
        method: 'GET',
        data: imageData
      },
      video_: {
        url: 'video',
        method: 'GET',
        data: videoData
      },

    };
    return publicFunc.urlAddPrefix(url, prefix);
  })
  .service('osgPrefixService', function (httpService, osgPrefixUrl, localStorageService) {
    this.imagePrefix = function () {
      return httpService.http({}, osgPrefixUrl.image_, {}).then(function (data) {
        if (data && data.errcode === 0 ) {
          localStorageService.set('osgImageData', data.data.prefix);
          return data.data.host;
        }
        else {
          return data
        }
      })
    };
    this.videoPrefix = function () {
      return httpService.http({}, osgPrefixUrl.video_, {}).then(function (data) {
        if (data && data.errcode === 0 ) {
          localStorageService.set('osgVideoData', data.data.prefix);
          return data.data.host;
        }
        else {
          return data
        }
      })
    };







  });
